package com.myt.matp.gui;

public final class UIMenu extends UIList {

    UIWidget m_Panel = null;

    protected UIMenu(int id, GUI gui) {
	super(id, gui);
    }

    public final int getType() {
	return UIWidget.MENU;
    }

    public void addOption(int id, String label) {
	UIItem item = m_Gui.createUIItem(id);
	item.setText(label);
	add(item);
    }

    protected void setAdjustedTo(UIWidget uiw) {
	m_Panel = uiw;
    }

    protected boolean isAdjustedInto(UIWidget uiw) {
    	return uiw.equals(m_Panel);
    }

    protected void adjustIn(int w, int h) {
	resize(w, h);
	// Best height
	if (getSize() > 0) {
	    int avgHiCtrl = getContentHeight() / getSize();
	    int n = h / avgHiCtrl;
	    h = n * avgHiCtrl + getMinHeight();
	}	    
	h = Math.min(h, getMinHeight() + getContentHeight());
	// New dimension
	setArea(w, h);
    }
}